package com.example.demo.Interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;

/**
 * 配置拦截器
 * @author jq
 *
 */
public class SessionInterceptor  implements HandlerInterceptor{
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
        if(request.getRequestURI().equals("/user/login")||request.getRequestURI().equals("/fail.html")){
        	return true;
        }
        Object obj = request.getSession().getAttribute("user");
        if(obj!=null){
        	return true;
        }
        else{
        	response.sendRedirect("/fail.html");
        	return false;
        }
	}
}
